package gameEngine.agents.observationSystem.analyzer;

import org.apache.log4j.Logger;

import gameEngine.agents.observationSystem.samples.Sample;
import gameEngine.agents.teamMateModel.AgentMock;
import gameEngine.agents.teamMateModel.TeamMateModel;
/**
 * Analyze by Max result, meaning agent competence will be his best result
 * @author alon
 *
 */
public class MaxAnalyzer implements ObservationAnalyzer {

	private TeamMateModel teamateModel;
	Logger log = Logger.getLogger(gameEngine.agents.Logger.Massages.MassageFactory.class);
	private EpsilonAnalyzer epsilonAnalyzer;
	
	
	public MaxAnalyzer(TeamMateModel teamateModel) {
		super();
		this.teamateModel = teamateModel;
		epsilonAnalyzer=new EpsilonAnalyzer(teamateModel);
	}

	/**
	 * if observation competence is larger then one in {@link TeamMateModel}
	 * replace it by new one 
	 */
	public void analyze(Sample observation) {
		if(observation == null){ 
			log.debug("observation is null, failed to analyze.");
			return; 
		}
		//take the agentMok (representation of agent) from the teamateModel 
		int id = observation.getID();
		AgentMock agentMock = teamateModel.getAgentById(id);
		
		// new competence
		double compitance = agentMock.getAgentCompitance();
		if(compitance<observation.getScore()){
			agentMock.setAgentCompitance(observation.getScore());
		}
		epsilonAnalyzer.analyze(observation);
	}
	
	public MaxAnalyzer clone(){
		return new MaxAnalyzer(teamateModel.clone()); 
	}
	
	public MaxAnalyzer initAnalyzer(TeamMateModel model){
		return new MaxAnalyzer(model);
	}

}
